/**
 * @file LayerManager.hpp
 *
 * @date 12/02/2012
 * @author Tales 
 *
 */

#ifndef LAYERMANAGER_HPP_
#define LAYERMANAGER_HPP_

#include "Manager.hpp"
#include "common.hpp"
#include <set>

using std::set;

namespace wolf {

// Forward declaration save lives
class Layer;

/**
 * @brief Manages all the layers
 * @ingroup stdMod
 *
 *
 * It's an abstract base class. If you do not create an instance before first layer creation, it
 *  will instantiate the subclass ActorManager.
 *
 */
class WOLF_DECLSPEC LayerManager: public Manager {
public:
	/**
	 * @brief Ordinary destructor
	 */
	virtual ~LayerManager();

	/**
	 * @brief Gets the current instance
	 * @return the instance. If there is none, it creates a ActorManager and return it.
	 */
	static LayerManager &getInstance();

	void onDraw(Engine &engine, SDL_Surface *dst);

protected:
	/**
	 * @brief Default (and unique) constructor.
	 */
	LayerManager();
private:
	static LayerManager *instance;
	set<Layer*, bool(*)(Layer*, Layer*)> layers;

	friend class Layer;

	/**
	 * @brief Adds a new layer on engine
	 *
	 * This layer will be automatically put on their right order according with its depth.
	 **/
	void addLayer(Layer & layer);
	/**
	 * @brief Removes a layer
	 *
	 * The Layer's destructor calls it so you did not have to worry about
	 *  segment fault or something like that.
	 * @see @ref MemoryManagement
	 **/
	void removeLayer(Layer & layer);
	/**
	 * @brief Returns if the layer has been added
	 *
	 *
	 **/
	bool hasLayer(Layer & layer);
};

} /* namespace wolf */
#endif /* LAYERMANAGER_HPP_ */
